package com.itheima.web;

import com.itheima.R;
import com.itheima.pojo.UmsResourceCategory;
import com.itheima.service.UmsResourceCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 袁鹏
 * @date 2022-10-13-12:27
 */
@RestController
@RequestMapping("/resourceCategory")
public class UmsResourceCategoryController {

    @Autowired
    private UmsResourceCategoryService umsResourceCategoryService;


    /**
     * 添加后台资源分类
     */
    @PostMapping("/create")
    public R create(@RequestBody UmsResourceCategory resourceCategory){
        umsResourceCategoryService.create(resourceCategory);
        return R.success(null);
    }


    /**
     * 根据id删除后台资源分类
     */
    @PostMapping("/delete/{id}")
    public R delete(@PathVariable("id") Long id) {
        umsResourceCategoryService.delete(id);
        return R.success(id);
    }


    /**
     * 查询所有后台资源分类
     */
    @GetMapping("/listAll")
    public R listAll(){
        List<UmsResourceCategory> resourceCategoryList = umsResourceCategoryService.listAll();
        return R.success(resourceCategoryList);
    }


    /**
     * 修改后台资源分类
     */
    @PostMapping("/update/{id}")
    public R update(@PathVariable("id") Long id, @RequestBody UmsResourceCategory resourceCategory) {
        umsResourceCategoryService.update(id, resourceCategory);
        return R.success(null);
    }
}
